<template>
	<view class="bind">
		<view class="item">
			<view class="tit">
				姓名 <text>(不可修改)</text>
			</view>
			<view class="val">

				{{name}}
			</view>
		</view>

		<u-form :model="model" ref="uForm" :rules="rules" label-position="top">
			<view class="item">
				<!-- 	<view class="tit">
					账号
				</view> -->

				<u-form-item :border-bottom="false" label="账号" style="width:100% ;" prop="acount">

					<view class="val" style="width:100% ;">
						<u-input style="width:95% ;" maxlength='40' placeholder="请输入支付宝账号" v-model="model.acount"
							type="text" />


					</view>
				</u-form-item>

			</view>
		</u-form>
		<view class="btns">
			<view class="botBox">

				<view class="itemBtn next">
					<u-button shape="circle" type="error" @click="submit" :ripple="true" ripple-bg-color="#d7d8da">绑定
					</u-button>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				name: "",

				model: {
					acount: "",
				},
				rules: {
					acount: [{
						required: true,
						message: '请输入支付宝账号',
						// 可以单个或者同时写两个触发验证方式 
						trigger: ['change', 'blur'],
					}, {
						// 自定义验证函数，见上说明
						validator: (rule, value, callback) => {
							// 上面有说，返回true表示校验通过，返回false表示不通过
							// this.$u.test.mobile()就是返回true或者false的
							return !/[\u4E00-\u9FA5]/.test(value);
						},
						message: '不能包含中文',
						// 触发器可以同时用blur和change
						trigger: ['change', 'blur'],
					}]
				}
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		onLoad() {
			this.getlist()
		},
		methods: {
			submit() {
				// if (!this.model.acount) {
				// 	uni.showToast({
				// 		icon: "none",
				// 		title: "请输入支付宝账号",
				// 		duration: 3000
				// 	})
				// 	return

				// }


				this.$refs.uForm.validate(valid => {
					if (valid) {
						this.$u.api.cashAccountbind({
								cashAccountType: 'ALIPAY',
								accountNo: this.model.acount,

							})
							.then(res => {
								if (res.code == 'ok') {
									uni.navigateBack()
								} else {
									uni.showToast({
										icon: "none",
										title: res.msg,
										duration: 3000
									})
								}
							});

					} else {
						console.log('验证失败');
					}
				});






			},
			getlist() {

				this.$u.api
					.realNameGet()
					.then((res) => {
						this.name = res.data
					});

			}
		}
	}
</script>

<style scoped lang="scss">
	/deep/ .u-form-item--left__content__label {
		font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
		font-weight: 400;
		font-size: 28rpx;
		color: rgba(15, 20, 23, 0.6);
		line-height: 33rpx;
		margin-bottom: 12rpx;
	}

	.bind {
		padding: 50rpx 80rpx;

		.botBox {
			z-index: 8;
			position: fixed;
			left: 40rpx;
			bottom: 90rpx;
			padding-bottom: env(safe-area-inset-bottom);
			right: 40rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.itemBtn {
				flex: 1;


				&.next {
					border-radius: 44rpx 44rpx 44rpx 44rpx;
					box-shadow: 0rpx 20rpx 24rpx 0rpx rgba(181, 36, 44, 0.2);
				}
			}
		}

		.item {
			margin-bottom: 42rpx;

			.tit {
				font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
				font-weight: 400;
				font-size: 28rpx;
				color: rgba(15, 20, 23, 0.6);
				line-height: 33rpx;
				margin-bottom: 12rpx;

				text {
					padding: 0 0 0 10rpx;
					font-size: 24rpx
				}
			}

			.val {
				height: 80rpx;
				background: rgba(232, 230, 229, 0.12);
				border-radius: 44rpx 44rpx 44rpx 44rpx;
				border: 2rpx solid #F1F1F1;
				font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
				font-weight: 500;
				font-size: 28rpx;
				color: #0F1417;
				padding-left: 30rpx;
				display: flex;
				align-items: center;
			}
		}
	}
</style>
